package server.cmd;


import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import server.dao.TbProjectDAO;
import server.dao.TbUserDAO;
import server.vo.TbProjectVO;
import server.vo.TbUserVO;
import server.vo.TbExpenseVO;


public class TbProjectCmd {
	
	
	/**
	 * Project List By User ID
	 * @param request 
	 * @param Connection
	 * @throws Exception
	 */
	
	public String getPjtListByUserId(Connection conn, String param_id) throws Exception {
	
		TbProjectVO tbProjectVO = new TbProjectVO();
		TbUserVO tbUserVO = new TbUserVO();
		TbProjectDAO tbProjectDAO = new TbProjectDAO();
		List<TbProjectVO> projectList = null;
		String szMsg ="";

		tbUserVO.setUser_id(param_id);	
		
		try {
		
			projectList = tbProjectDAO.getPjtListByUserId(conn, tbUserVO);
			for (int i=0; i<projectList.size(); i++)
			{
				tbProjectVO = projectList.get(i);
				szMsg += tbProjectVO.getProject_code()+"|";
				szMsg += tbProjectVO.getProject_name()+"|";
				szMsg += tbProjectVO.getProject_begindate()+"|";
				szMsg += tbProjectVO.getProject_finishdate()+"^";
			}
		
			return szMsg;	
			
		} catch(Exception e) {
			throw e;
		}	
		
	}
	
	
	/**
	 * Project View By Project Code
	 * @param request 
	 * @param Connection
	 * @throws Exception
	 */
	
	public String getPjtViewByPjtCode(Connection conn, String param_code) throws Exception {
	
		TbProjectVO tbProjectVO = new TbProjectVO();
		TbProjectDAO tbProjectDAO = new TbProjectDAO();
		String szMsg ="";

		tbProjectVO.setProject_code(param_code);	
		
		try {
		
			tbProjectVO = tbProjectDAO.getPjtViewByPjtCode(conn, tbProjectVO);
			if(tbProjectVO != null)
			{
				//tbProjectVO = projectList.get(i);
				szMsg += tbProjectVO.getProject_code()+"|";
				szMsg += tbProjectVO.getProject_name()+"|";
				szMsg += tbProjectVO.getProject_begindate()+"|";
				szMsg += tbProjectVO.getProject_finishdate()+"^";
			}
			/*
			userList = tbUserDAO.getUserListByUserId(conn, tbUserVO);
			
			for(TbUserVO iter : userList){
				szMsg += iter.getUser_id() + "|" + iter.getUser_name() + "|" + iter.getUser_pwd() + "|" + iter.getLogin_date() + "^";			
			}*/
		
			return szMsg;	
			
		} catch(Exception e) {
			throw e;
		}	
		
	}
	
	/**
	 * getPjtListAll TB_PROJECT 리스트 조회
	 * @param conn
	 * @return String 
	 * @throws Exception 
	 */
	public String getPjtListAll(Connection conn) throws Exception {
		
		
		TbProjectDAO tbProjectDAO = new TbProjectDAO();
		
		List<TbProjectVO> pjtList = null;
		String szMsg ="";
		
		pjtList = tbProjectDAO.getPjtListAll(conn);
		
		for(TbProjectVO iter : pjtList){
			szMsg += iter.getProject_code() + "|" + iter.getProject_name() + "|" + iter.getProject_begindate() + "|" + iter.getProject_finishdate() + "^";			
		}
		
		return szMsg;
	}
	
	/**
	 * Project List By Project Code
	 * @param request 
	 * @param Connection
	 * @throws Exception
	 */
	
	public String getAcntListByPjtCode(Connection conn, String param_code) throws Exception {
	
		TbProjectVO tbProjectVO = new TbProjectVO();
		TbExpenseVO tbExpenseVO = new TbExpenseVO();
		TbProjectDAO tbProjectDAO = new TbProjectDAO();
		List<TbExpenseVO> expenseList = null;
		String szMsg ="";

		tbProjectVO.setProject_code(param_code);
		
		try {
		
			expenseList = tbProjectDAO.getAcntListByPjtCode(conn, tbProjectVO);
			for (int i=0; i<expenseList.size(); i++)
			{
				tbExpenseVO = expenseList.get(i);
				szMsg += tbExpenseVO.getAcnt_name()+"|";
				szMsg += tbExpenseVO.getAcnt_amount()+"|";
				szMsg += tbExpenseVO.getAcnt_balance()+"^";
			}
		
			return szMsg;	
			
		} catch(Exception e) {
			throw e;
		}	
		
	}
	
}
